<template>
  <d2-container :filename="filename">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="真实姓名">
        <el-input v-model="form.Realname"></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="form.Nickname"></el-input>
      </el-form-item>
      <el-form-item label="用户名">
         <el-input v-model="form.Username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
         <el-input v-model="form.Userpwd"></el-input>
      </el-form-item>
       <el-form-item label="QQ">
         <el-input v-model="form.Qq"></el-input>
      </el-form-item>
       <el-form-item label="微信">
         <el-input v-model="form.Weixin"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="Phone">
         <el-input v-model="form.Phone"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
         <el-input v-model="form.Email"></el-input>
      </el-form-item>
      <el-form-item label="身份证">
         <el-input v-model="form.Idcard"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSubmit">保存</el-button>
        <el-button @click="handleCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
import { mapActions } from 'vuex'
import { SaveUserData } from '@/api/sys/user'
import { validateMobile } from '@/libs/validateRules'
import util from '@/libs/util'
export default {
  // name 值和本页的 $route.name 一致才可以缓存页面
  name: 'sys-user-add',
  components: {
  },
  data () {
    return {
      filename: __filename,
      form: {
        Userid: 0,
        Realname: '',
        Nickname: '',
        Username: '',
        Phone: '',
        Userpwd: '',
        Sex: 0,
        Qq: '',
        Weixin: '',
        Email: '',
        Idcard: '',
        Lastloginip: '',
        Lastlogintime: ''
      },
      rules: {
        Phone: [
          {
            validator: validateMobile,
            message: '电话号码格式不正确',
            trigger: 'blur'
          }
        ]
      },
      loading: false
    }
  },
  created: function () {
  },
  methods: {
    ...mapActions('d2admin/page', [
      'closeCurrent'
    ]),
    handleSubmit () {
      var _t = this
      util.SaveData(SaveUserData, this.form, _t, function () {
        _t.handleCancel()
      })
    },
    handleCancel () {
      this.closeCurrent({
        vm: this
      })
    }
  }
}
</script>
